﻿@using Apps.Web.Core;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<div class="mvctool">
<input id="txtQuery" type="text" class="searchText" />
@Html.ToolButton("btnQuery", "fa fa-search", Resource.Query,ref perm, "Query", true)
@Html.ToolButton("btnCreate", "fa fa-plus", "创建表单",ref perm, "Create", true)
@Html.ToolButton("btnEdit", "fa fa-pencil", "修改表单",ref perm, "Edit", true)
@Html.ToolButton("btnEditStep", "fa fa-forward", "1.设计步骤",ref perm, "Edit", true)
@Html.ToolButton("btnEditStepRule", "fa fa-forward", "2.设计分支",ref perm, "Edit", true)
@Html.ToolButton("btnEditLayout", "fa fa-forward", "3.设计布局",ref perm, "Edit", true)
@Html.ToolButton("btnDetails", "fa fa-list", "查看详情",ref perm, "Details", true)
@Html.ToolButton("btnDelete", "fa fa-trash", Resource.Delete,ref perm, "Delete", true)
</div>
<table id="List"></table>

<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
@Html.Partial("~/Views/Shared/_Partial_AutoGrid.cshtml")
<script type="text/javascript">
    $(function () {
        $('#List').datagrid({
            url: '@Url.Action("GetList")',
            width: SetGridWidthSub(10),
            methord: 'post',
            height:  SetGridHeightSub(37),
            fitColumns: true,
            sortName: 'Id',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            rownumbers: true,//行号
            columns: [[
                { field: 'Id', title: 'ID', width: 80, hidden: true },
                { field: 'Name', title: '名称', width: 80, sortable: true },
                { field: 'Remark', title: '备注', width:180, sortable: true },
                { field: 'UsingDep', title: '使用部门', width: 80, sortable: true },
                { field: 'IsExternal', title: '外部来源', width: 55, align: 'center', formatter: function (value) { return CustomFormatter(value,"是","否") } },
                { field: 'ExternalURL', title: '来源地址', width: 180, sortable: true },
                { field: 'TypeName', title: '所属', width: 80, sortable: true },
                { field: 'AttrA', title: '可用程度', width: 80, sortable: true , align: 'center', formatter: function (value,row) { if(value!=null || row.IsExternal==true) return EnableFormatterMes(true,"已完成"); else return EnableFormatterMes(false,"不完整") } },
                { field: 'State', title: '是否启用', width: 35, align: 'center', formatter: function (value) { return EnableFormatter(value) } },
                { field: 'CreateTime', title: '创建时间', width: 80, sortable: true }

            ]]
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").datagrid('load');
        else
            $("#List").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {

        $("#btnCreate").click(function () {
            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='auto' frameborder='0'' src='@Url.Action("Create")'></iframe>");
            $("#modalwindow").window({ title: '设计表单', width: 700, height: 448, iconCls: 'fa fa-plus' }).window('open');
        });
        $("#btnEditLayout").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='100%'  frameborder='0' src='@Url.Action("FormLayout")?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '编辑表单布局', width: 800, height: 548, fit:true, iconCls: 'fa fa-pencil' }).window('open');
            } else { $.messageBox5s(Lang.Tip, Lang.PleaseSelectTheOperatingRecord); }
        });
        $("#btnEdit").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='100%'  frameborder='0' src='@Url.Action("Edit")?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '编辑表单', width: 700, height: 448, iconCls: 'fa fa-pencil' }).window('open');
            } else { $.messageBox5s(Lang.Tip, Lang.PleaseSelectTheOperatingRecord); }
        });
        $("#btnEditStep").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='100%'  frameborder='0' src='@Url.Action("EditStep")?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '设计步骤 [ 每次操作自动保存,请谨慎操作 ]', width: 900, height: 448, iconCls: 'fa fa-pencil' }).window('open');
            } else { $.messageBox5s(Lang.Tip, Lang.PleaseSelectTheOperatingRecord); }
        });
        $("#btnEditStepRule").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='100%'  frameborder='0' src='@Url.Action("StepList")?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '设计分支', width: 900, height: 433, iconCls: 'fa fa-pencil' }).window('open');
            } else { $.messageBox5s(Lang.Tip, Lang.PleaseSelectTheOperatingRecord); }
          });
        $("#btnDetails").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.modalWindow(Lang.Details, '@Url.Action("Details")?id=' + row.Id + '&Ieguid=' + GetGuid(), 500, 380, 'fa fa-list');
            } else { $.messageBox5s(Lang.Tip, Lang.PleaseSelectTheOperatingRecord); }
        });
        $("#btnQuery").click(function () {
            var queryStr = $("#txtQuery").val();
            if (queryStr == null) {
                queryStr = "%";
            }
            $("#List").datagrid("load", { queryStr: encodeURI(queryStr) });

        });
        $("#btnDelete").click(function () {
            dataDelete("@Url.Action("Delete")", "List");
	    });
    });
</script>
